import { faker } from "@faker-js/faker";
import { ChannelItem, ChannelDetail } from '../src/types/data'

const createChannels = () => {
  const channels: ChannelItem[] = [];
  for (let i = 0; i < 10; i++) {
    channels.push({
      id: `${i + 1}`,
      name: faker.music.songName(),
    });
  }
  return channels;
};

const createChannelDetailById = (channelId: string) => {
  const infoList: { channel: string; data: ChannelDetail[] }[] = [];
  for (let i = 0; i < 10; i++) {
    const result: ChannelDetail[] = [];
    for (let j = 0; j < 50; j++) {
      result.push({
        id: faker.string.uuid(),
        username: faker.internet.userName(),
        email: faker.internet.email(),
        avatar: faker.image.avatar(),
        password: faker.internet.password(),
        birthdate: faker.date.birthdate(),
        registeredAt: faker.date.past(),
      });
    }
    infoList.push({
      channel: i + '',
      data: result
    })
  }
  return infoList.find(item => item.channel === channelId)?.data;
};

export default [
  {
    url: "/api/channels",
    method: "get",
    response: () => {
      return { data: createChannels(), message: "ok" };
    },
  },
  {
    url: "/api/channel/:id",
    method: "get",
    response: (params: { query: { id: string } }) => {
      const id = params.query.id || (Math.floor(Math.random() * 10) + '');
      return { data: createChannelDetailById(id), message: "ok" };
    },
  },
];
